class SubrestsController < ApplicationController
  before_filter(:get_restaurant)

  def create
    # Create a subrest object that has
    # been instantiated with attributes
    # and linked to the rest object
    @subrest = @restaurant.subrests.build(params[:subrest])
    @subrest.img = session[:url]
    if @subrest.save
      flash[:notice] = 'subrest was successfully created.'
      respond_to do |format|
        format.html { redirect_to restaurant_url(@restaurant) }
        format.xml  { render :xml => @subrest,
          :status => :created, :location => @restaurant }
      end
    else
      flash[:notice] = 'subrest was not created.'
      respond_to do |format|
        format.html { redirect_to restaurant_url(@restaurant) }
        format.xml  { render :xml => @subrest.errors,
          :status => :unprocessable_entity }
      end
    end
  end

private

  def get_restaurant
     @restaurant = Restaurant.find(params[:restaurant_id])
  end
end
